package cn.rokhdelar.ams.business.biz.project.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.rokhdelar.ams.business.biz.project.domain.po.BizWxReport;
import cn.rokhdelar.ams.business.biz.project.domain.vo.BizWxReportAddVo;
import cn.rokhdelar.ams.business.biz.project.domain.vo.ManagerReportPageVo;
import cn.rokhdelar.ams.business.biz.project.domain.vo.WxReportPageVo;
import cn.rokhdelar.ams.business.biz.project.mapper.BizWxReportMapper;
import cn.rokhdelar.ams.business.biz.project.service.WxReportService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author 范书铭
 * @date 2025年07月17日 14:27
 */
@Service
public class WxReportServiceImpl extends ServiceImpl<BizWxReportMapper, BizWxReport> implements WxReportService {
    @Override
    public void wxUserSubmitReport(BizWxReportAddVo wxReportAddVo) {
        BizWxReport bizWxReport = new BizWxReport();
        BeanUtil.copyProperties(wxReportAddVo, bizWxReport);
        save(bizWxReport);
    }

    @Override
    public void deleteReport(String wxOpenId, String reportId) {
        remove(new LambdaQueryWrapper<>(BizWxReport.class).eq(BizWxReport::getWxOpenId, wxOpenId).eq(BizWxReport::getId, reportId));
    }

    @Override
    public IPage<BizWxReport> getWxUserReportList(WxReportPageVo pageQuery) {
        Page<BizWxReport> page = new Page<>(pageQuery.getCurrent(), pageQuery.getSize());
        LambdaQueryWrapper<BizWxReport> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BizWxReport::getWxOpenId, pageQuery.getWxOpenId());
        IPage<BizWxReport> pageList = baseMapper.selectPage(page, wrapper);
        return pageList;
    }


    @Override
    public IPage<BizWxReport> getReportListByStatus(ManagerReportPageVo pageQuery) {
        Page<BizWxReport> page = new Page<>(pageQuery.getCurrent(), pageQuery.getSize());
        LambdaQueryWrapper<BizWxReport> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BizWxReport::getStatus, pageQuery.getStatus());
        IPage<BizWxReport> pageList = baseMapper.selectPage(page, wrapper);
        return pageList;
    }

    @Override
    public void updateReportStatus(String reportId, String status) {
        BizWxReport bizWxReport = new BizWxReport();
        bizWxReport.setId(reportId);
        bizWxReport.setStatus(status);
        updateById(bizWxReport);
    }

    @Override
    public void changeToLawEnforcement(String reportId) {
        BizWxReport bizWxReport = new BizWxReport();
        bizWxReport.setId(reportId);
        bizWxReport.setStatus("2");
        updateById(bizWxReport);
        // TODO 发送通知给执法人员
    }
}
